#!/bin/bash

randStdin() {
    local line
    while read line ; do
        echo ${RANDOM}_$line
    done | sort -n | sed -nr 's/^[0-9]+_//p'
}

join -a1 <(randStdin < leader.txt | cat -n)                     \
         <(diff <(sed -n -r 's/^[0-9]+://p' list.txt | sort)   \
                <(sort leader.txt)                              \
            | grep '<' | sed 's/< //' | randStdin              \
            | awk '{s=int((NR-1)/3)+1; if (s>7)s=7; print s, $0}')

